﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using WindowsAPI.Windows;

namespace WindowsAPI
{
    public partial class ExtendedForm : Form, INotifyPropertyChanged
    {
        /* ------------------------------------------------------------------------------------------ */

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string PropertyName) { OnPropertyChanged(new PropertyChangedEventArgs(PropertyName)); }
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            switch(e.PropertyName)
            {
                case "CanMove":
                    OnCanMoveChanged(EventArgs.Empty);
                    break;
            }

            var lv_Handlers = PropertyChanged;
            if(lv_Handlers != null)
                lv_Handlers(this, e);
        }

        public event EventHandler CanMoveChanged;
        protected virtual void OnCanMoveChanged(EventArgs e)
        {
            var lv_Hanldes = CanMoveChanged;
            if(lv_Hanldes != null)
                lv_Hanldes(this, e);
        }

        /* ------------------------------------------------------------------------------------------ */

        private bool f_CanMove;

        /* ------------------------------------------------------------------------------------------ */

        public bool CanMove { get { return f_CanMove; } set { f_CanMove = value; OnPropertyChanged("CanMove"); } }

        /* ------------------------------------------------------------------------------------------ */

        public ExtendedForm() { InitializeComponent(); }

        /* ------------------------------------------------------------------------------------------ */

        //protected override void WndProc(ref Message m)
        //{
        //    if(m.Msg == (int)WM.NCLBUTTONDOWN)
        //    {
        //        //Проверяем где именно нажали кнопку мыши
        //        var result = User32.SendMessage(m.HWnd, WM.NCHITTEST, IntPtr.Zero, m.LParam);
        //        if(result == HTCAPTION)
        //            //Не позволяем этому сообщению быть обработанным
        //            return;
        //    }
        //    base.WndProc(ref m);
        //}


        /* ------------------------------------------------------------------------------------------ */
    }
}
